package com.intellij.licensecommon.net.impl;

import com.intellij.licensecommon.net.Address;

import java.net.*;
import java.util.Enumeration;

public class b implements Address {
    private final InetSocketAddress socketAddress;

    public b(SocketAddress socketAddress) {
        this.socketAddress = (InetSocketAddress) socketAddress;
    }

    public InetSocketAddress getStocketAddress() {
        return this.socketAddress;
    }

    public String toString() {
        return this.socketAddress.toString();
    }

    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof b)) {
            return false;
        }
        b localb = (b) other;
        if (this.socketAddress == null ? localb.socketAddress != null : !this.socketAddress.equals(localb.socketAddress)) {
            return false;
        }
        return true;
    }

    public int hashCode() {
        return this.socketAddress == null ? 0 : this.socketAddress.hashCode();
    }

    public String getName() {
        InetAddress addr = getInetAddress();
        return addr.getHostName() + " (" + addr.getHostAddress() + ")";
    }

    public boolean isLoopback() {
        InetAddress address = getInetAddress();
        if ((address != null) && (address.isLoopbackAddress())) {
            return true;
        }
        try {
            Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
            while (nis.hasMoreElements()) {
                NetworkInterface ni = nis.nextElement();
                Enumeration<InetAddress> addrs = ni.getInetAddresses();
                while (addrs.hasMoreElements()) {
                    InetAddress addr = addrs.nextElement();
                    if (addr.equals(address)) {
                        return true;
                    }
                }
            }
        } catch (SocketException localSocketException) {
        }
        return false;
    }

    public InetAddress getInetAddress() {
        return getStocketAddress().getAddress();
    }
}
